package com.iheima.web;

import com.iheima.domain.PageBean;
import com.iheima.domain.User;
import com.iheima.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns="/pageQuery")
public class UserPageQueryServlet extends HttpServlet {
    private UserService userService =new UserService();
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String pageNumberStr = request.getParameter("pageNumber");
        String pageSizeStr = request.getParameter("pageSize");
        int pageNumber = 1;
        if(pageNumberStr!=null&&!"".equals(pageNumberStr)){
            pageNumber = Integer.parseInt(pageNumberStr);
        }
        int pageSize= 5;
        if(pageSizeStr!=null&&!"".equals(pageSizeStr)){
            pageSize= Integer.parseInt(pageSizeStr);
        }
        PageBean<User> pageBean=userService.pageQuery(pageSize,pageNumber);
        request.setAttribute("pageBean",pageBean);
        request.getRequestDispatcher("/list_page.jsp").forward(request,response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}